package com.oplink.webbase.modules.cfg.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import com.oplink.webbase.modules.sys.utils.inf.IDict;

/**
 * Configuration Network Element Entity
 * 
 * @author yizhang
 */
@Entity
@Table(name = "cfg_ne")
@DynamicInsert
@DynamicUpdate
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class CfgNe implements IDict {

	// ID
	private Long nid;

	// 网元名称
	private String nename;

	// ip地址
	private String ip;

	// 最大机盘数
	private int maxslot;

	// 网元类型
	private CfgNeType netype;

	// 所属站点
	private CfgSite site;

	// 是否启用
	private String enable;

	// 所属类型
	private String type;

	// 是否离线
	private String offline;

	/**
	 * 如果网元离线则采用这样的策略。
	 * 网元离线，将该网元所有的告警恢复，然后产生网元离线告警。
	 * 网元在线，将该网元的离线告警恢复，然后读取并产生该网元的所有当前告警。
	 * 即网元离线告警优先级最高。
	 */
	// @JSONField(serialize = false)
	// List<AlarmCurrent> acurlist = Lists.newArrayList();

	@JSONField(serialize = false)
	List<CfgSlot> slotlist = Lists.newArrayList();

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getEnable() {
		return enable;
	}

	public String getOffline() {
		return offline;
	}

	public void setOffline(String offline) {
		this.offline = offline;
	}

	public void setEnable(String enable) {
		this.enable = enable;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getNid() {
		return nid;
	}

	public void setNid(Long nid) {
		this.nid = nid;
	}

	public String getNename() {
		return nename;
	}

	public void setNename(String nename) {
		this.nename = nename;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public int getMaxslot() {
		return maxslot;
	}

	public void setMaxslot(int maxslot) {
		this.maxslot = maxslot;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "netype")
	@NotFound(action = NotFoundAction.IGNORE)
	@JsonIgnore
	public CfgNeType getNetype() {
		return netype;
	}

	public void setNetype(CfgNeType netype) {
		this.netype = netype;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "site")
	@NotFound(action = NotFoundAction.IGNORE)
	public CfgSite getSite() {
		return site;
	}

	public void setSite(CfgSite site) {
		this.site = site;
	}

	// @OneToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE }, fetch = FetchType.EAGER,
	// mappedBy = "nenode")
	// @NotFound(action = NotFoundAction.IGNORE)
	// // @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	// public List<AlarmCurrent> getAcurlist() {
	// return acurlist;
	// }
	//
	// public void setAcurlist(List<AlarmCurrent> acurlist) {
	// this.acurlist = acurlist;
	// }

	@OneToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE }, fetch = FetchType.LAZY, mappedBy = "nenode")
	@NotFound(action = NotFoundAction.IGNORE)
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	@JsonIgnore
	public List<CfgSlot> getSlotlist() {
		return slotlist;
	}

	public void setSlotlist(List<CfgSlot> slotlist) {
		this.slotlist = slotlist;
	}

	public void setLabel(String label) {
	}

	public void setValue(String value) {
	}

	@Transient
	@Override
	public String getLabel() {
		return "" + nename;
	}

	@Transient
	@Override
	public String getValue() {
		return "" + nid;
	}

	public static final String STATUS_ONLINE = "1";
	public static final String STATUS_OFFLINE = "0";
	public static final String OFFLINE_ALARMNAME = "nodeOffline";
	public static final int OFFLINE_ALARMSERVERITY = 10;

}